package com.biz.service.weixin;

import java.net.URLDecoder;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;


import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;
import com.biz.utils.URLConectionUtil;
import com.framework.util.Const;
import com.framework.util.Tools;
  /*************************************************************************
 * 版本：         V1.0  
 *
 * 文件名称 ：TokenService.java 描述说明 ：
 * 
 * 创建信息 : create by wanglun on 2016-3-24 下午5:20:42  修订信息 : modify by ( ) on (date) for ( )
 * 
 * 版权信息 : Copyright (c) 2015 扬州北斗软件有限公司
 **************************************************************************/
@Service("tokenService")
public class TokenService {
	
	public static String getToken() throws Exception{
		
		/*String newAccessToken = "";
		String accessTokenStr = Tools.readTxtFile(Const.ZF_TICKET);
		
		if ("".equals(accessTokenStr))
		{
			//System.out					.println("########载入JsApiTicket空，重新载入###################");
			newAccessToken = getTocken();
		}
		else
		{
			String[] accessTokenArg = accessTokenStr.split(",");
			long nowTime = new Date().getTime();
			long putTime = Long.parseLong(accessTokenArg[1]);
			long diffTime = Long.parseLong(accessTokenArg[2]);
			if (Math.abs(nowTime - putTime) >= diffTime)
			{
				//System.out						.println("######载入token已超时，重新载入####################");
				newAccessToken = getTocken();
			} else
			{
				newAccessToken = accessTokenArg[0];
			}
		}
		return newAccessToken;*/
		return null;
	}

	 public static void main(String args[]) throws Exception { 
		 getToken();
	    } 
	 
	 
	 
	
	
	/**
	 * 平台token
	 * @throws Exception
	 */
	private static String getTocken()throws Exception
	{
		Map<String, String> map = new HashMap<String, String>();
		Map<String, String> map2 = new HashMap<String, String>();
		

		/*map2.put("platform", Const.platform);
		map2.put("secret", Const.secret);

		
		map.put("jsonParams", JSON.toJSONString(map2));
		String x = URLConectionUtil.httpURLConnectionPostDiy(Const.TokenUrl, map);
		x = URLDecoder.decode(x, "utf-8");
		Map<String, String> map1 = JSON.parseObject(x, Map.class);
		
		Tools.writeFile(Const.ZF_TICKET, map1.get("token") + ","
				+ new Date().getTime() + "," + (Integer.valueOf(map1.get("diffTime")) * 1000));
		
		return  map1.get("token");*/
		return  null;
	}
	
	
}
